<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/gamemanage'}"><i class="el-icon-menu"></i> 赛事管理</el-breadcrumb-item>
                <el-breadcrumb-item>选手管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <el-button size="small" type="primary" style="margin-bottom:5px"  @click="exportToExcel()">导出到EXCEL</el-button>

        <el-table :data="tableData" border  style="width: 100%"

                  @select="handleselect"
                  @select-all="handleselectall"
        >
            <el-table-column
                    type="selection"
                    width="80">
            </el-table-column>
            <el-table-column prop="player.realName" label="真实姓名" sortable width="130">
            </el-table-column>
            <el-table-column prop="player.nickName" label="昵称" sortable width="130">
            </el-table-column>
            <el-table-column prop="player.idCard" label="身份证号" sortable width="250">
            </el-table-column>
            <el-table-column prop="player.mobile" label="手机号" sortable width="180">
            </el-table-column>
            <el-table-column prop="player.email" label="邮箱" sortable width="180">
            </el-table-column>
            <el-table-column prop="player.personalSign" label="个人签名" sortable width="180">
            </el-table-column>
            <el-table-column prop="fabulousCount" label="点赞数" sortable width="180">
            </el-table-column>
            <el-table-column prop="voteCount" label="投票数" sortable width="180">
            </el-table-column>
            <el-table-column label="操作" width="300">
                <template scope="scope">
                    <el-button size="small" type="danger"
                               @click="auditNoPass(scope.$index, scope.row)">不通过</el-button>
                    <el-button size="small" type="warning"
                               @click="handleImg(scope.$index, scope.row)">查看选手图集</el-button>
                </template>
            </el-table-column>



            

        </el-table>

        <div class="pagination">
            <el-pagination
                    layout="total,prev, pager, next"
                    :current-page.sync="currentPage"
                    :total="total">
            </el-pagination>
        </div>

        <el-button size="small" type="danger" style="margin-bottom:5px"  @click="auditNoPassAll()">批量审核不通过</el-button>

        <div>
            <el-dialog title="选手图集" v-model="formVisible">
                <div style="margin:0 auto;" v-for="img in gameUserImg">
                    <img style="width:300px;height:300px;margin-left: 35%;" class="pre-img"  :src="$prefix+img.imgUrl" alt="">

                </div>


                <div slot="footer" class="dialog-footer">
                    <el-button @click="formVisible = false">关闭</el-button>
                </div>
            </el-dialog>

        </div>


    </div>
</template>

<script>
    import { Loading } from 'element-ui';
    export default {
        data() {
            return {
                player:{

                    realName:"",
                    nickName:"",
                    idCard:"",
                    mobile:"",
                    email:"",
                    personalSign:""
                },
                total:0,
                currentPage:1,
                tableData: [],
                attendRecordIds:"",
                gameUserImg:[],
                formVisible:false
            }
        },

        methods: {
            handleImg(index,row){
                this.gameUserImg = this.tableData[index].gameUserImg;

                console.log(this.gameUserImg);

                this.formVisible = true;
            },
            getSelectAttendRecordId(selection){
                let self = this;
                self.attendRecordIds = "";
                for (let i = 0;i<selection.length;i++){
                    if(i==selection.length-1){
                        self.attendRecordIds += selection[i].attendRecordId ;
                    }
                    else {
                        self.attendRecordIds += selection[i].attendRecordId + ",";
                    }

                }
                console.log(self.attendRecordIds);
            },
            changeStatus(attendRecordIds,status){
                let self = this;
                let params = {
                    attendRecordIds:attendRecordIds,
                    status:status
                }
                self.$req.pput(self.$api("AttendRecord")+"auditStatus",self,function(res){

                  self.getData();

                },params,true)
            },
            handleselect(selection, row){
                this.getSelectAttendRecordId(selection);

            },
            handleselectall(selection, row){
                this.getSelectAttendRecordId(selection);
            },
            auditPass(index,row){

                this.changeStatus(row.attendRecordId,1);

            },
            auditNoPass(index,row){
                this.changeStatus(row.attendRecordId,2);

            },
            auditPassAll(){
                this.changeStatus(this.attendRecordIds,1);

            },
            auditNoPassAll(){
                this.changeStatus(this.attendRecordIds,2);

            },


            getData(){
                let gameId = this.$route.query.gameId;

                let self = this;
                let params = {
                    gameId:gameId,
                    page:self.currentPage,
                    status:1
                };

                self.$req.pget(self.$api("AttendRecord")+"getAttendRecordByPage",self,function(res){

                    console.log(res.data.data.content)
                    self.tableData = res.data.data.content;
                    self.total = res.data.data.totalElements;

                },params,true)
            },
            exportToExcel(){
                let self = this;
                let gameId = this.$route.query.gameId;
                let params = {
                    gameId:gameId,
                    status:1
                };

                window.open(self.$api("ExportExcel")+"playList?gameId="+gameId+"&status=1");


            }
        },
        mounted:function(){
            this.getData();
        }
    }
</script>